﻿/*============================================
 * 类名 :Expression
 * 描述 :
 *   
 * 创建时间: 2011-2-5 10:38:33
 * Blog:   http://home.cnblogs.com/xiangism
 *============================================*/
using System;
using System.Collections.Generic;

using System.Text;

namespace SuperCalculator
{
    /// <summary>表达式</summary>
    class Expression
    {
        public Expression() { }
        public Expression( string value )
        {
            //this._format = value;
            //Head = Syntax.Analyse( lexical.Analyse( value ) );
            this.Format = value;
        }
        string _format;
        /// <summary>表达式的字符串形式</summary>
        public String Format
        {
            get { return _format; }
            set
            {
                this._format = value;
                _format = _format.Replace( " ", "" );
                _format = _format.Replace( "\n", "" );
                if ( _format == string.Empty )
                    throw new ExpressionException( "空表达式" );
                Head = Syntax.Analyse( lexical.Analyse( value ) );
            }
        }
        Lexical lexical = new Lexical();
        /// <summary>树形表达式的头节点</summary>
        public Node Head { get; set; }

        /// <summary>求值</summary>
        public BigNumber Calculator()
        {
            // sd dfasfsdfasdf
            return Head.Value;
        }

    }
}
